package com.fdb.efp.nls.api.rest;

import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.web.controller.AbstractController;
import com.fdb.efp.nls.service.facade.PrdRateStdService;
import com.fdb.efp.nls.service.vo.PrdRateStdVO;
import com.fdb.efp.e4a.service.facade.SRoleDataRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/api")
public class PrdRateStdController extends AbstractController  {
	
	@Autowired
	@Qualifier("prdRateStdService")
	private PrdRateStdService prdRateStdService;
	@Autowired
	@Qualifier("sRoleDataRuleService")
	private SRoleDataRuleService sRoleDataRuleService;
	
	/**
	 * 列表数据查询
	 */
	@RequestMapping(value="/prd/rate/stds", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<PrdRateStdVO>> queryPrdRateStdAll(
			@RequestBody PrdRateStdVO vo) {		
		setUserInfoToVO(vo);
		List<PrdRateStdVO> outputVo =  prdRateStdService.queryAllOwner(vo);
		// 根据用户角色获取用户权限方案
		/** 【不符合switch规范】
		 * String dataAuthority = sRoleDataRuleService.getDataRuleType(httpRequest.getRequestURI(), getUserRoles());
		List<PrdRateStdVO> outputVo = null;
		DataRuleType dataRuleType = DataRuleType.getDataRuleType(dataAuthority);

		// 根据权限方案调用不同的方案进行数据查询
		switch (dataRuleType) {
		case Owner:
			outputVo = prdRateStdService.queryAllOwner(vo);
			break;
		【方法未实现】
		case CurrOrg:
			outputVo = prdRateStdService.queryAllCurrOrg(vo);
			break;
		case CurrDownOrg:
			outputVo = prdRateStdService.queryAllCurrDownOrg(vo);
			break;
		default:
			outputVo = prdRateStdService.queryAllOwner(vo);
			break;
		}*/
		for (PrdRateStdVO prdRateStdVO : outputVo) {
			prdRateStdVO.setRate(prdRateStdVO.getRate().multiply(new BigDecimal("100")));
		}
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键查询详情
	 */
	@RequestMapping(value="/prd/rate/std/{rateTypeId}", method=RequestMethod.GET)
	public @ResponseBody ResponseData<PrdRateStdVO> queryByPk(@PathVariable("rateTypeId") String rateTypeId) {		
		PrdRateStdVO inVo = new PrdRateStdVO();
				inVo.setRateTypeId(rateTypeId);
		PrdRateStdVO outputVo = prdRateStdService.queryByPk(inVo);
		return getResponseData(outputVo);
		
	}

	/**
	 * 根据主键删除信息
	 */
	@RequestMapping(value="/prd/rate/std", method=RequestMethod.DELETE)
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody PrdRateStdVO inPrdRateStdVo) {
		setUserInfoToVO(inPrdRateStdVo);
		int outputVo = prdRateStdService.deleteByPk(inPrdRateStdVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键更新信息
	 */
	@RequestMapping(value="/prd/rate/std", method=RequestMethod.PUT)
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody PrdRateStdVO inPrdRateStdVo) {
		setUserInfoToVO(inPrdRateStdVo);
		int outputVo = prdRateStdService.updateByPk(inPrdRateStdVo);
		return getResponseData(outputVo);
		
	}

	/**
	 * 根据主键更新信息
	 */
	@RequestMapping(value="/prd/rate/std/status", method=RequestMethod.PUT)
	public @ResponseBody ResponseData<Integer> setStatus(@RequestBody PrdRateStdVO inPrdRateStdVo) {
		setUserInfoToVO(inPrdRateStdVo);
		int outputVo = prdRateStdService.setStatusByPk(inPrdRateStdVo);
		return getResponseData(outputVo);

	}
	
	/**
	 * 新增数据
	 */
	@RequestMapping(value="/prd/rate/std", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertPrdRateStd(@RequestBody PrdRateStdVO inPrdRateStdVo) {
		setUserInfoToVO(inPrdRateStdVo);
		int outputVo = prdRateStdService.insertPrdRateStd(inPrdRateStdVo);
		return getResponseData(outputVo);

	}

}
